set more off

use JJPS_Flexibility_June2023.dta, clear

***=== Making variables for duration model ===
***(1) Interruption1***********
gen fail1=.
replace fail1=1 if interruption1=="Yes"
replace fail1=0 if interruption1=="No"

gen mon_signed = ""
replace mon_signed = "jan" if monthsigned == 1
replace mon_signed = "feb" if monthsigned == 2
replace mon_signed = "mar" if monthsigned == 3
replace mon_signed = "apr" if monthsigned == 4
replace mon_signed = "may" if monthsigned == 5
replace mon_signed = "jun" if monthsigned == 6
replace mon_signed = "jul" if monthsigned == 7
replace mon_signed = "aug" if monthsigned == 8
replace mon_signed = "sep" if monthsigned == 9
replace mon_signed = "oct" if monthsigned == 10
replace mon_signed = "nov" if monthsigned == 11
replace mon_signed = "dec" if monthsigned == 12

gen origin_date1=string(daysigned)+mon_signed+string(yearsigned)
gen date0signed=date(origin_date1, "DMY")
format date0signed %d
drop mon_signed
drop origin_date1

gen mon_sign_interrupted = ""
replace mon_sign_interrupted = "jan" if month_interrupted1 == 1
replace mon_sign_interrupted = "feb" if month_interrupted1 == 2
replace mon_sign_interrupted = "mar" if month_interrupted1 == 3
replace mon_sign_interrupted = "apr" if month_interrupted1 == 4
replace mon_sign_interrupted = "may" if month_interrupted1 == 5
replace mon_sign_interrupted = "jun" if month_interrupted1 == 6
replace mon_sign_interrupted = "jul" if month_interrupted1 == 7
replace mon_sign_interrupted = "aug" if month_interrupted1 == 8
replace mon_sign_interrupted = "sep" if month_interrupted1 == 9
replace mon_sign_interrupted = "oct" if month_interrupted1 == 10
replace mon_sign_interrupted = "nov" if month_interrupted1 == 11
replace mon_sign_interrupted = "dec" if month_interrupted1 == 12

gen fail_date1=string(day_interrupted1)+mon_sign_interrupted+string(year_interrupted1)
gen date1signed=date(fail_date1, "DMY")
format date1signed %d
drop mon_sign_interrupted
drop fail_date1

gen censored1=0
replace censored1=1 if year_interrupted1==2008 & month_interrupted1==12 & day_interrupted1==31

stset date1signed, failure(fail1==1) origin(time date0signed) id(agreementid) time0(date0signed)
stdes
*==> It will lead to missing _t because some events fail as it starts
gen date1signed2 = date1signed+1
stset date1signed2, failure(fail1==1) origin(time date0signed) id(agreementid) time0(date0signed)
stdes


***Table2. Model1
stcox Enforce JointCommittee Nonenforce ArmedNonsignatories AgreementGov NumSignatories WarType Timing_warend, schoenfeld(sch*) scaledsch(sca*) efron nohr

drop sch* sca*

***Table2. Model2
stcox Flexibility Enforce JointCommittee Nonenforce ArmedNonsignatories AgreementGov NumSignatories WarType Timing_warend, schoenfeld(sch*) scaledsch(sca*) efron nohr


drop sch* sca*



***=== Making variables for duration model ===
***(2) Interruption2***********
gen fail2=.
replace fail2=1 if interruption2=="Yes"
replace fail2=0 if interruption2=="No"

gen mon_eif = ""
replace mon_eif = "jan" if eif_month == 1
replace mon_eif = "feb" if eif_month == 2
replace mon_eif = "mar" if eif_month == 3
replace mon_eif = "apr" if eif_month == 4
replace mon_eif = "may" if eif_month == 5
replace mon_eif = "jun" if eif_month == 6
replace mon_eif = "jul" if eif_month == 7
replace mon_eif = "aug" if eif_month == 8
replace mon_eif = "sep" if eif_month == 9
replace mon_eif = "oct" if eif_month == 10
replace mon_eif = "nov" if eif_month == 11
replace mon_eif = "dec" if eif_month == 12

gen origin_date2=string(eif_day)+mon_eif+string(eif_year)
gen date0eif=date(origin_date2, "DMY")
format date0eif %d
drop mon_eif
drop origin_date2


gen mon_eif_interrupted = ""
replace mon_eif_interrupted = "jan" if month_interrupted2 == 1
replace mon_eif_interrupted = "feb" if month_interrupted2 == 2
replace mon_eif_interrupted = "mar" if month_interrupted2 == 3
replace mon_eif_interrupted = "apr" if month_interrupted2 == 4
replace mon_eif_interrupted = "may" if month_interrupted2 == 5
replace mon_eif_interrupted = "jun" if month_interrupted2 == 6
replace mon_eif_interrupted = "jul" if month_interrupted2 == 7
replace mon_eif_interrupted = "aug" if month_interrupted2 == 8
replace mon_eif_interrupted = "sep" if month_interrupted2 == 9
replace mon_eif_interrupted = "oct" if month_interrupted2 == 10
replace mon_eif_interrupted = "nov" if month_interrupted2 == 11
replace mon_eif_interrupted = "dec" if month_interrupted2 == 12

gen fail_date2=string(day_interrupted2)+mon_eif_interrupted+string(year_interrupted2)
gen date1eif=date(fail_date2, "DMY")
format date1eif %d
drop mon_eif_interrupted
drop fail_date2

gen censored2=0
replace censored2=1 if year_interrupted2==2008 & month_interrupted2==12 & day_interrupted2==31


stset date1eif, failure(fail2==1) origin(time date0eif) id(agreementid) time0(date0eif)
stdes
**==> It will lead to missing _t because some events fail as it starts
gen date1eif2 = date1eif+1
stset date1eif2, failure(fail2==1) origin(time date0eif) id(agreementid) time0(date0eif)
stdes


***Table3. Model1
stcox Enforce JointCommittee Nonenforce ArmedNonsignatories AgreementGov NumSignatories WarType Timing_warend, schoenfeld(sch*) scaledsch(sca*) efron nohr

drop sch* sca*

***Table3. Model2
stcox Flexibility Enforce JointCommittee Nonenforce ArmedNonsignatories AgreementGov NumSignatories WarType Timing_warend, schoenfeld(sch*) scaledsch(sca*) efron nohr


drop sch* sca*

